package com.gxa.logistics.controller;

import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.DepartmentReqListDTO;
import com.gxa.logistics.domain.dto.DepartmentSaveDTO;
import com.gxa.logistics.domain.dto.DepartmentUpdateDTO;
import com.gxa.logistics.domain.vo.DepartmentVO;
import com.gxa.logistics.service.DepartmentService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户管理-部门设置")
@RestController
@RequestMapping("/department")
@Slf4j
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 获取用户列表
     */
    @ApiOperation(value = "获取部门列表-分页", notes = "获取部门列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo",value = "当前页码数",defaultValue = "1",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "10",paramType = "query",dataType = "String")
    })
    @PostMapping("/list")
    public RespResult<PageWrapperDTO<DepartmentVO>> list(@RequestBody DepartmentReqListDTO departmentReqListDTO){
        return departmentService.list(departmentReqListDTO);
    }

    @GetMapping("/find")
    public RespResult<List<DepartmentVO>> find(){
        return RespResult.success(departmentService.findAll());
    }

    /**
     * 新增员工
     */
    @ApiOperation(value = "新增保存", notes = "新增保存")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data",value = "新增部门实体") @Validated DepartmentSaveDTO departmentSaveDTO) {
        // 保存
        departmentService.insertDepartment(departmentSaveDTO);
        return RespResult.success();
    }

    /**
     * 修改用户
     */
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data",value = "修改部门实体") DepartmentUpdateDTO departmentUpdateDTO) {
        departmentService.updateDepartment(departmentUpdateDTO);
        return RespResult.success();
    }


    /**
     * 删除用户
     */
    @ApiOperation(value = "删除部门", notes = "删除部门")
    @ApiImplicitParam(name = "dept_id",value = "部门id",required = true,dataType = "String",paramType = "path")
    @PostMapping("/delete/{dept_id}")
    public RespResult delete(@PathVariable("dept_id") Integer deptId){
        departmentService.deleteDepartmentById(deptId);
        return RespResult.success();
    }




}
